package com.cn.xiaonuo.slbfinances.slbproxys.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cn.xiaonuo.common.entity.BusinessMessage;
import com.cn.xiaonuo.dbs.core.annotation.DataSource;
import com.cn.xiaonuo.slbfinances.slbproxys.mapper.CmProxyInfoMapper;
import com.cn.xiaonuo.slbfinances.slbproxys.service.ICoverageProxyInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class CoverageProxyInfoServiceImpl extends ServiceImpl<CmProxyInfoMapper, String> implements ICoverageProxyInfoService {

    @Autowired
    private CmProxyInfoMapper cmProxyInfo;

    /*财务管理-进账--农家餐饮--全部订单交易--查看详情*/
    @Override
    @DataSource(name = "jyb_soole_data_hn")
    public BusinessMessage successOrderInfoOne(String serialNumber) {
        BusinessMessage message = new BusinessMessage();
        try {
            List<Map<String, Object>> list = cmProxyInfo.successOrderInfoOne(serialNumber);
            PageInfo<Map<String, Object>> agentList = new PageInfo<>(list);
            if (agentList.getList() != null && agentList.getList().size() > 0) {
                message.setSuccess(true);
                message.setData(agentList);
                message.setMessage("操作成功");
            } else {
                message.setSuccess(false);
                message.setMessage("暂无数据");
            }
        } catch (Exception e) {
            message.setSuccess(false);
            message.setMessage("暂无数据");
        }
        return message;
    }

    /*财务管理-进账--农家餐饮--全部订单交易--订单列表*/
    @Override
    @DataSource(name = "jyb_soole_data_hn")
    public BusinessMessage successOrderInfo(Integer pageSize, Integer pageNum, Long beginTime, Long endTime){
        BusinessMessage message = new BusinessMessage();
        try {
            String beginTimes = null;
            String endTimes = null;
            if (beginTime != null && endTime != null) {
                beginTimes = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(beginTime));
                endTimes = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(endTime));
            }
            if (null == pageNum || pageNum <= 1) {
                pageNum = 1;
            }
            if (null == pageSize || pageSize <= 1) {
                pageSize = 10;
            }
            // 设置分页参数
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> list = cmProxyInfo.successOrderInfo(beginTimes, endTimes);
            PageInfo<Map<String, Object>> agentList = new PageInfo<>(list);
            if (agentList.getList() != null && agentList.getList().size() > 0) {
                message.setSuccess(true);
                message.setData(agentList);
                message.setMessage("操作成功");
            } else {
                message.setSuccess(false);
                message.setMessage("暂无数据");
            }
        } catch (Exception e) {
            message.setSuccess(false);
            message.setMessage("暂无数据");
        }
        return message;
    }

    /*财务管理-进账--农家餐饮--商家入驻--进账明细*/
    @Override
    @DataSource(name = "jyb_soole_data_hn")
    public BusinessMessage receiptsDetail(Integer pageSize, Integer pageNum, Long beginTime, Long endTime, String realName, String phone, String recordWay){
        BusinessMessage message = new BusinessMessage();
        String beginTimes = null;
        String endTimes = null;
        try {
            if (beginTime != null |endTime != null) {
                try {
                    beginTimes = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date(beginTime));
                    endTimes = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date(endTime));
                } catch (Exception e) {
                    message.setSuccess(false);
                    message.setMessage("请选择开始与结束时间！");
                    return message;
                }
            }
            if (null == pageNum || pageNum <= 1) {
                pageNum = 1;
            }
            if (null == pageSize || pageSize <= 1) {
                pageSize = 10;
            }
            // 设置分页参数
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> list = cmProxyInfo.receiptsDetail(beginTimes, endTimes, realName, phone, recordWay);
            PageInfo<Map<String, Object>> agentList = new PageInfo<>(list);
            if (agentList.getList() != null && agentList.getList().size() > 0) {
                message.setSuccess(true);
                message.setData(agentList);
                message.setMessage("操作成功");
            } else {
                message.setSuccess(false);
                message.setMessage("暂无数据");
            }
        } catch (Exception e) {
            message.setSuccess(false);
            message.setMessage("暂无数据");
        }
        return message;
    }

    /*财务管理-进账--农家餐饮--商家入驻--列表*/
    @Override
    @DataSource(name = "jyb_soole_data_hn")
    public BusinessMessage merchantsInfo(Integer pageSize, Integer pageNum, String  createTime,String endTime, String status, String name, String realName, String phone) {
        BusinessMessage message = new BusinessMessage();
        try {
            if (createTime == null) {
                message.setSuccess(false);
                message.setMessage("开始时间未传入");
                return message;
            }
                if (endTime==null){
                    message.setSuccess(false);
                    message.setMessage("结束时间未传入");
                    return message;
                }


            if (null == pageNum || pageNum <= 1) {
                pageNum = 1;
            }
            if (null == pageSize || pageSize <= 1) {
                pageSize = 10;
            }
            // 设置分页参数
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> list = cmProxyInfo.merchantsInfo(createTime,endTime, status, name, realName, phone);
            PageInfo<Map<String, Object>> agentList = new PageInfo<>(list);
            if (agentList.getList() != null && agentList.getList().size() > 0) {
                message.setSuccess(true);
                message.setData(agentList);
                message.setMessage("操作成功");
            } else {
                message.setSuccess(false);
                message.setMessage("暂无数据");
            }
        } catch (Exception e) {
            message.setSuccess(false);
            message.setMessage("暂无数据");
        }
        return message;
    }
}

